package com.spring;

import com.example.demo.bean.Book;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.annotation.Resource;

public class SpringTest1 {

    @Resource(name = "book2")
    private Book book2;

    public static void main(String[] args) {
        ApplicationContext context=new ClassPathXmlApplicationContext("bean.xml");
        Book book1 = context.getBean("book1", Book.class);
        System.out.println(book1.getId());
    }

    @Test
    public void test1(){
        ApplicationContext context=new ClassPathXmlApplicationContext("bean.xml");
        Book book2 = context.getBean("book2", Book.class);
        System.out.println(book2.getId());
    }

    @Test
    public void test2(){
        ApplicationContext context=new ClassPathXmlApplicationContext("bean.xml");
        SpringTest1 springTest1=new SpringTest1();
        Book book2 = springTest1.book2;
        System.out.println(book2.getId());
    }
}
